How to add characters to reach the maximum size of a char[].
Posted
by
Bon_chan
on Stack Overflow
See other posts from Stack Overflow
or by Bon_chan
Published on 2010-12-21T16:27:44Z
Indexed on
2010/12/21
16:54 UTC
Read the original article
Hit count: 208
Hi folks,
I have the following part of code :
for(int i=0;i<n;i++)
{
printf("Student %d\n",i+1);
printf("Enter name : ");
scanf("%s",&(student+i)->name);
fflush(stdin);
lengthName = strlen((student+i)->name);
while(lengthName !='\0')
{
}}
when the length is shorter than 10, it will add hyphens until reaching the maximum size. Ex : John =>> 6 hyphens will be added
I know how to do it in csharp but can't figure it out in c. Could some of you give me some lights please?
PS : Oh yes the variable name is char name[10+1] and it a part of the structure called student.
© Stack Overflow or respective owner